#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
文件读写操作
"""


class Fib(object):

    def __init__(self):
        self.__a, self.__b = 0, 1

    def __iter__(self):
        return self

    def __next__(self):
        __x = self.__a
        self.__a, self.__b = self.__b, self.__a + self.__b
        if self.__a > 10000:
            raise StopIteration
        return __x


def write(s):
    with open('Fib.txt', 'a', encoding='utf-8', errors='ignore') as f:
        f.write(str(s)+'\n')


def main():
    fib = Fib()
    for i in fib:
        print(i)
        write(i)
        if i > 1000:
            break


if __name__ == "__main__":
    main()
